{
Traviesadora beta 0.2.0.13.33 (30.11.2008)
LastMod: 21.12.2008 by Prof1983

Copyright 2008, travieorama@googlemail.com

This file is part of the taviesadora project

taviesadora is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

taviesadora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
}
unit InputWin;

interface

uses
  Classes, Controls, Dialogs, ExtCtrls, Forms, Graphics, Messages, StdCtrls, SysUtils, Variants, Windows;

type
  TfrmTravInputBox = class(TForm)
    lblDiagText: TLabel;
    Bevel1: TBevel;
    Image1: TImage;
    lblCaption: TLabel;
    imgClose: TImage;
    edtInput: TEdit;
    procedure btnOKClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure imgCloseClick(Sender: TObject);
    procedure imgCloseMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure imgCloseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure edtInputKeyPress(Sender: TObject; var Key: Char);
  private
    btnOK: TButton;
    btnCancel: TButton;
  private
    XOrig: Integer;
    YOrig: Integer;
  protected
    procedure DoCreate(); override;
  public
    constructor Init(ACaption, APrompt: string; HideInput: Boolean);
  end;

var
  frmTravInputBox: TfrmTravInputBox;

function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;

implementation

{$R *.dfm}

function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
begin
  frmTravInputBox := TfrmTravInputBox.Create(Application);
  try
    frmTravInputBox.Init(ACaption, APrompt, Value = 'pw');
    frmTravInputBox.edtInput.Text := Value;
    Result := (frmTravInputBox.ShowModal = mrOk);
    Value := frmTravInputBox.edtInput.Text;
  finally
    frmTravInputBox.Free();
  end;
end;

{ TfrmTravInputBox }

procedure TfrmTravInputBox.btnOKClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TfrmTravInputBox.btnCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TfrmTravInputBox.DoCreate();
begin
  inherited;

  btnOK := TButton.Create(Self);
  btnOK.Parent := Self;
  btnOK.Left := 104;
  btnOK.Top := 96;
  btnOK.Width := 75;
  btnOK.Height := 25;
  btnOK.Caption := 'OK';
  btnOK.Font.Charset := DEFAULT_CHARSET;
  btnOK.Font.Color := clWindowText;
  btnOK.Font.Height := -11;
  btnOK.Font.Name := 'MS Sans Serif';
  btnOK.Font.Style := [];
  btnOK.TabOrder := 1;
  btnOK.TabStop := True;
  btnOK.OnClick := btnOKClick;

  btnCancel := TButton.Create(Self);
  btnCancel.Parent := Self;
  btnCancel.Left := 248;
  btnCancel.Top := 96;
  btnCancel.Width := 75;
  btnCancel.Height := 25;
  btnCancel.Caption := 'Cancel';
  btnCancel.Font.Charset := DEFAULT_CHARSET;
  btnCancel.Font.Color := clWindowText;
  btnCancel.Font.Height := -11;
  btnCancel.Font.Name := 'MS Sans Serif';
  btnCancel.Font.Style := [];
  btnCancel.TabOrder := 2;
  btnCancel.TabStop := True;
  btnCancel.OnClick := btnCancelClick;
end;

procedure TfrmTravInputBox.edtInputKeyPress(Sender: TObject; var Key: Char);
begin
  if (key = #13) then
  begin
    btnOKClick(btnOK);
    key := #0;
  end;
end;

procedure TfrmTravInputBox.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  XOrig := +x;
  YOrig := +y;
  image1.Tag := 1;
end;

procedure TfrmTravInputBox.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if (Image1.Tag = 1) then
  begin
    left := +left-(XOrig-x);
    top := +top-(YOrig-y);
  end;
end;

procedure TfrmTravInputBox.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  image1.Tag := 0;
end;

procedure TfrmTravInputBox.imgCloseClick(Sender: TObject);
begin
  btnCancelClick(btnCancel);
end;

procedure TfrmTravInputBox.imgCloseMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (imgClose.Tag = 1) then
  begin
    imgClose.Top := imgClose.Top-1;
    imgClose.left := imgClose.left-1;
    imgClose.Tag := 0;
  end;
end;

procedure TfrmTravInputBox.imgCloseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  imgClose.Top := imgClose.Top + 1;
  imgClose.left := imgClose.left + 1;
  imgClose.Tag := 1;
end;

constructor TfrmTravInputBox.Init(ACaption, APrompt: string; HideInput: Boolean);
begin
  if HideInput then
  begin
    edtInput.Font.Name := 'Wingdings';
    edtInput.PasswordChar := 'l';
  end;
  lblCaption.Caption := ACaption;
  lblDiagText.Caption := APrompt;
  lblDiagText.Left := 70;
  lblDiagText.Width := Width-lblDiagText.Left * 2;
  imgClose.Left := Width-imgClose.Width - 2;
  Image1.Left := 1;
  Image1.Width := imgClose.Left - Image1.Left;
end;

end.
